package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.EmployeeRoomService;
import com.the4man.cnbdw.utils.Page;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.DataGrid;
import com.the4man.framework.model.EmployeeRoom;
import com.the4man.framework.model.EmployeeRoomExample;
import com.the4man.framework.util.DateUtil;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Action(
        value = "employeeRoomAction",
        results = {@Result(
                name = "addPage",
                location = "/cnbdw/employeeRoom/add.jsp"
        ), @Result(
                name = "listPage",
                location = "/cnbdw/employeeRoom/list.jsp"
        ), @Result(
                name = "editPage",
                location = "/cnbdw/employeeRoom/edit.jsp"
        )}
)
public class EmployeeRoomAction extends BaseAction implements ModelDriven<EmployeeRoom> {
    private EmployeeRoom employeeRoom = new EmployeeRoom();
    @Autowired
    private EmployeeRoomService employeeRoomService;

    public EmployeeRoomAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public String toAddPage() {
        return "addPage";
    }

    public String toEditPage() {
        return "editPage";
    }

    public void getAllDatasourceList() {
        try {
            EmployeeRoomExample employeeRoomExample = new EmployeeRoomExample();
            this.employeeRoomService.countByExample(employeeRoomExample);
            Page<EmployeeRoom> page = new Page();
            this.setPageProperties(page);
            this.employeeRoomService.selectByExample(employeeRoomExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var5) {
            LOG.error("获取数据失败", var5, new String[0]);
        }

    }

    public void add() {
        PageJson json = new PageJson();

        try {
            String time = DateUtil.getInstance().formatDate(new Date());
            this.employeeRoomService.insert(this.employeeRoom);
            json.setReturnFlag(true);
            json.setReturnMsg("提交成功！");
        } catch (Exception var3) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var3, new String[0]);
        }

        this.writeJson(json);
    }

    public void update() {
        PageJson json = new PageJson();

        try {
            this.employeeRoomService.updateByPrimaryKey(this.employeeRoom);
            json.setReturnFlag(true);
            json.setReturnMsg("提交成功！");
        } catch (Exception var3) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var3, new String[0]);
        }

        this.writeJson(json);
    }

    public String executeModifyResult() {
        try {
            Object instance = this.employeeRoomService.selectByPrimaryKey(this.employeeRoom.getId(), EmployeeRoom.class);
            this.getRequest().setAttribute("instance", instance);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

        return "modifyPage";
    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            int i = this.employeeRoomService.deleteByPrimaryKey(this.getRequest().getParameter("ids"), EmployeeRoom.class);
            if(i > 0) {
                json.setReturnMsg("删除EmployeeRoom_info成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("删除EmployeeRoom_info失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var3) {
            LOG.error("批量删除EmployeeRoom_info失败！", var3, new String[0]);
            json.setReturnMsg("删除EmployeeRoom_info失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void verify() {
        PageJson json = new PageJson();
        this.writeJson(json);
    }

    public EmployeeRoom getModel() {
        return this.employeeRoom;
    }
}